/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package sonia.golf.dao.sqlite;

//~--- non-JDK imports --------------------------------------------------------

import sonia.golf.dao.DAOListener;
import sonia.golf.dao.GenericDAO;

//~--- JDK imports ------------------------------------------------------------

import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Sebastian Sdorra
 *
 * @param <T>
 * @param <K>
 */
public abstract class AbstractSQLiteDAO<T, K> implements GenericDAO<T, K>
{

  /**
   * Method description
   *
   *
   * @param listener
   */
  public void addListener(DAOListener<T> listener)
  {
    synchronized (listeners)
    {
      listeners.add(listener);
    }
  }

  /**
   * Method description
   *
   *
   * @param listener
   */
  public void removeListener(DAOListener<T> listener)
  {
    synchronized (listeners)
    {
      listeners.add(listener);
    }
  }

  /**
   * Method description
   *
   *
   * @param item
   * @param event
   */
  protected void fireEvent(T item, DAOListener.DAOEvent event)
  {
    for (DAOListener listener : listeners)
    {
      listener.onEvent(item, event);
    }
  }

  //~--- fields ---------------------------------------------------------------

  /** Field description */
  private final Set<DAOListener<T>> listeners = new HashSet<DAOListener<T>>();
}
